﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BotonJXC.Entity;
using BotonJXC.DAO;
using BotonJXC.Util;
using NHibernate;

namespace BotonJXC.BLL
{
    public class SettleAccountsBLL : BaseBLL<SettleAccountsDAO,SettleAccounts,int>
    {
        /// <summary>
        /// 保存结算款单
        /// </summary>
        /// <param name="settleAccounts"></param>
        /// <returns></returns>
        public bool saveSettleAccounts(SettleAccounts settleAccounts)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {
                base.Dao.Save(settleAccounts);
                trans.Commit();
                return true;
            }
            catch (Exception)
            {
                trans.Rollback();
                throw;

            }
            finally
            {
                HBHelper.Close();
            }
        }

        /// <summary>
        /// 保存结算款单
        /// </summary>
        /// <param name="settleAccounts"></param>
        /// <returns></returns>
        public bool delSettleAccounts(SettleAccounts settleAccounts)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {
                base.Dao.Delete(settleAccounts);
                trans.Commit();
                return true;
            }
            catch (Exception)
            {
                trans.Rollback();
                throw;

            }
            finally
            {
                HBHelper.Close();
            }
        }

        /// <summary>
        /// 更新结算款单
        /// </summary>
        /// <param name="settleAccounts"></param>
        /// <returns></returns>
        public bool updateSettleAccounts(SettleAccounts settleAccounts)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {
                base.Dao.Update(settleAccounts);
                trans.Commit();
                return true;
            }
            catch (Exception)
            {
                trans.Rollback();
                return false;
            }
            finally
            {
                HBHelper.Close();
            }
        }


        /// <summary>
        /// 条件查询结算款单
        /// </summary>
        /// <param name="begintime">开始制单时间</param>
        /// <param name="endtime">结束制单时间</param>
        /// <param name="settleAccounts">计算款单对象</param>
        /// <param name="start">开始页</param>
        /// <param name="count">查询条数</param>
        /// <returns></returns>
        public PageModel<SettleAccounts> findSettleAccountsByCondition(DateTime? begintime, DateTime? endtime, SettleAccounts settleAccounts, int start, int count)
        {
            return base.Dao.findSettleAccountsByCondition(begintime, endtime, settleAccounts, start, count);
        }

        /// <summary>
        /// 查找全部结算款单
        /// </summary>
        /// <returns></returns>
        public IList<SettleAccounts> findAllSettleAccounts()
        {
            return base.FindAll();
        }

        /// <summary>
        /// 根据款单ID查询
        /// </summary>
        /// <param name="orderid"></param>
        /// <returns></returns>
        public SettleAccounts findSettleAccountsById(string orderid)
        {
            return base.Get(Int32.Parse(orderid));
        }

    }
}
